all: add an 'only-child' pseudo-class selector
authorCosimo Cecchi <cosimoc@gnome.org>
Mon, 3 Oct 2011 21:09:09 +0000 (17:09 -0400)
committerCosimo Cecchi <cosimoc@gnome.org>
Tue, 4 Oct 2011 15:47:47 +0000 (11:47 -0400)
Add an :only-child pseudo-class selector, which selects single children
of a parent container.

https://bugzilla.gnome.org/show_bug.cgi?id=660833

gtk/gtkcssprovider.c
gtk/gtkcssselector.c
gtk/gtkenums.h
gtk/gtkwidgetpath.c

index a905f1a8b109ce8bc29b9c2a0ee131027a94f245..bd019157abbd3c449f88f9ea74bd9d3ebc50783b 100644 (file)
@@ -1987,6 +1987,7 @@ parse_selector_pseudo_class (GtkCssScanner  *scanner,
   } pseudo_classes[] = {
     { "first-child",  GTK_REGION_FIRST, 0 },
     { "last-child",   GTK_REGION_LAST, 0 },
+    { "only-child",   GTK_REGION_ONLY, 0 },
     { "sorted",       GTK_REGION_SORTED, 0 },
     { "active",       0, GTK_STATE_FLAG_ACTIVE },
     { "prelight",     0, GTK_STATE_FLAG_PRELIGHT },
index d300d41baaedd128811c7c1ba30dcc78c47b7ce1..2abe0923a7d5f3291253d89f0f2363ee83037416 100644 (file)
@@ -130,6 +130,7 @@ _gtk_css_selector_print (const GtkCssSelector *selector,
         "nth-child(odd)",
         "first-child",
         "last-child",
+        "only-child",
         "sorted"
       };
       guint i;
@@ -201,6 +202,8 @@ compute_region_flags_for_index (const GtkWidgetPath *path,
     flags |= GTK_REGION_FIRST;
   if (sibling_id + 1 == n_siblings)
     flags |= GTK_REGION_LAST;
+  if (n_siblings == 1)
+    flags |= GTK_REGION_ONLY;
 
   return flags;
 }
index a2428ab509864ac4e9165e5613ddba69f390bc87..dbc0e90ea09807e78590f1e5707a12f31f55edf2 100644 (file)
@@ -862,6 +862,7 @@ typedef enum
  * @GTK_REGION_ODD: Region has an odd number within a set.
  * @GTK_REGION_FIRST: Region is the first one within a set.
  * @GTK_REGION_LAST: Region is the last one within a set.
+ * @GTK_REGION_ONLY: Region is the only one within a set.
  * @GTK_REGION_SORTED: Region is part of a sorted area.
  *
  * Describes a region within a widget.
@@ -871,6 +872,7 @@ typedef enum {
   GTK_REGION_ODD     = 1 << 1,
   GTK_REGION_FIRST   = 1 << 2,
   GTK_REGION_LAST    = 1 << 3,
+  GTK_REGION_ONLY    = 1 << 4,
   GTK_REGION_SORTED  = 1 << 5
 } GtkRegionFlags;
 
index d0be6de63ede6af699fdd5ca71ae24ecf3ab6fc5..a694f7b07db7cde723399a6f93a00000ee30c899 100644 (file)
@@ -357,6 +357,7 @@ gtk_widget_path_to_string (const GtkWidgetPath *path)
                 "odd",
                 "first",
                 "last",
+                "only",
                 "sorted"
               };